(function() {

this.codium = this.codium || {};
this.codium.panel = this.codium.panel || {};

this.codium.panel.NewTicket = pasta.webgui.Panel.extend(
{
	init : function() 
	{
		this._super();
		
		this.canvas.style.background = "rgba(0, 0, 0, 0.4)";
		this.canvas.style.zIndex = "1000";
		
		this.service = new codium.CodiumService();
		
		this.pnl = new pasta.webgui.ContainerControl();
		this.pnl.setWidth(400);
		this.pnl.setHeight(370);
		this.pnl.setLeft((this.getWidth() - this.pnl.getWidth()) / 2);
		this.pnl.setTop((this.getHeight() - this.pnl.getHeight()) / 3);
		this.pnl.canvas.style.background = "rgba(255, 255, 255, 0.9)";
		this.pnl.canvas.style.border = "1px solid rgba(255, 255, 255, 1)";
		this.pnl.canvas.style.webkitBoxShadow = "0px 1px 8px #000000";
		this.pnl.canvas.style.mozBoxShadow = "0px 1px 8px #000000";
		this.pnl.canvas.style.boxShadow = "0px 1px 8px #000000";
		this.pnl.canvas.style.mozBorderRadius = "6px";
		this.pnl.canvas.style.webkitBorderRadius = "6px";
		this.pnl.canvas.style.borderRadius = "6px";
		this.addControl(this.pnl);
		
			this.lblTitle = new pasta.webgui.Label();
			this.lblTitle.setCaption(".: New Ticket");
			this.lblTitle.setWidth(this.pnl.getWidth());
			this.lblTitle.setTop(10);
			this.lblTitle.setLeft(10);
			this.lblTitle.font.setSize(16);
			this.lblTitle.font.setBold(true);
			this.pnl.addControl(this.lblTitle);
			
			this.btnCancel = new pasta.webgui.Button();
			this.btnCancel.setCaption("Cancel");
			this.btnCancel.setWidth(80);
			this.btnCancel.setTop(this.pnl.getHeight() - 40);
			this.btnCancel.setLeft(this.pnl.getWidth() - 85);
			this.btnCancel.getOnClick().setHandler(this, this.btnCancelClick);
			this.pnl.addControl(this.btnCancel);
			
			this.btnOK = new pasta.webgui.Button();
			this.btnOK.setCaption("OK");
			this.btnOK.setWidth(80);
			this.btnOK.setTop(this.btnCancel.getTop());
			this.btnOK.setLeft(this.btnCancel.getLeft() - 85);
			this.btnOK.getOnClick().setHandler(this, this.btnOKClick);
			this.pnl.addControl(this.btnOK);
			
			this.lblTitle = new pasta.webgui.Label();
			this.lblTitle.setLeft(10);
			this.lblTitle.setTop(40);
			this.lblTitle.setWidth(200);
			this.lblTitle.setCaption("Title :");
			this.lblTitle.font.setBold(true);
			this.pnl.addControl(this.lblTitle);
			
			this.edtTitle = new pasta.webgui.Edit();
			this.edtTitle.setLeft(this.lblTitle.getLeft());
			this.edtTitle.setTop(this.lblTitle.getTop() + 20);
			this.edtTitle.setWidth(this.pnl.getWidth() - (2 * this.edtTitle.getLeft()));
			this.pnl.addControl(this.edtTitle);
			
			this.lblDescription = new pasta.webgui.Label();
			this.lblDescription.setLeft(10);
			this.lblDescription.setTop(this.edtTitle.getTop() + 30);
			this.lblDescription.setWidth(200);
			this.lblDescription.setCaption("Description :");
			this.lblDescription.font.setBold(true);
			this.pnl.addControl(this.lblDescription);
			
			this.mmoDescription = new pasta.webgui.Memo();
			this.mmoDescription.setLeft(this.lblDescription.getLeft());
			this.mmoDescription.setTop(this.lblDescription.getTop() + 20);
			this.mmoDescription.setWidth(this.pnl.getWidth() - (2 * this.mmoDescription.getLeft()) - 2);
			this.mmoDescription.setHeight(100);
			this.pnl.addControl(this.mmoDescription);
			
			this.lblAsignee = new pasta.webgui.Label();
			this.lblAsignee.setLeft(10);
			this.lblAsignee.setTop(this.mmoDescription.getTop() + this.mmoDescription.getHeight() + 10);
			this.lblAsignee.setWidth(200);
			this.lblAsignee.setCaption("Assign To :");
			this.lblAsignee.font.setBold(true);
			this.pnl.addControl(this.lblAsignee);
			
			this.ddbAssignee = new pasta.webgui.DropDownBox();
			this.ddbAssignee.setLeft(this.lblAsignee.getLeft());
			this.ddbAssignee.setTop(this.lblAsignee.getTop() + 20);
			this.ddbAssignee.setWidth(this.pnl.getWidth() - (2 * this.ddbAssignee.getLeft()));
			this.pnl.addControl(this.ddbAssignee);
			
			this.lblPriority = new pasta.webgui.Label();
			this.lblPriority.setLeft(10);
			this.lblPriority.setTop(this.ddbAssignee.getTop() + 30);
			this.lblPriority.setWidth(200);
			this.lblPriority.setCaption("Priority :");
			this.lblPriority.font.setBold(true);
			this.pnl.addControl(this.lblPriority);
			
			this.ddbPriority = new pasta.webgui.DropDownBox();
			this.ddbPriority.setLeft(this.lblPriority.getLeft());
			this.ddbPriority.setTop(this.lblPriority.getTop() + 20);
			this.ddbPriority.setWidth(180);
			this.pnl.addControl(this.ddbPriority);
			
			this.ddbPriority.addItem("1", "Low");
			this.ddbPriority.addItem("2", "Medium");
			this.ddbPriority.addItem("3", "High");
			
			this.lblDueDate = new pasta.webgui.Label();
			this.lblDueDate.setLeft(200);
			this.lblDueDate.setTop(this.ddbAssignee.getTop() + 30);
			this.lblDueDate.setWidth(200);
			this.lblDueDate.setCaption("Due Date :");
			this.lblDueDate.font.setBold(true);
			this.pnl.addControl(this.lblDueDate);
			
			this.dpkDueDate = new pasta.webgui.DatePicker();
			this.dpkDueDate.setLeft(this.lblDueDate.getLeft());
			this.dpkDueDate.setTop(this.lblDueDate.getTop() + 20);
			this.dpkDueDate.setWidth(180);
			this.pnl.addControl(this.dpkDueDate);
		
		this.setVisible(false);
	},
	
	//--------------------- Service Event ---------------------
	
	//--------------------- Event ---------------------
	
	show : function()
	{
		this.initSize();
		
		this._super();
		
		this.edtTitle.setText("");
		this.mmoDescription.setText("");
		
		var target = this;
		this.service.listPeople(app.projectId, function(result) {target.updatePeople(result);});
	},
	
	updatePeople : function(list)
	{
		this.ddbAssignee.clear();
		
		for (var i = 0; i < list.length; i++)
		{
			var obj = list[i];
			
			this.ddbAssignee.addItem(obj.userId, obj.userName);
		}
	},
	
	initSize : function()
	{
		this.pnl.setLeft((this.getWidth() - this.pnl.getWidth()) / 2);
		this.pnl.setTop((this.getHeight() - this.pnl.getHeight()) / 3);
	},
	
	btnCancelClick : function(sender)
	{
		this.close();
	},
	
	btnOKClick : function(sender)
	{
		if (this._onOK != null)
			this._onOK.callHandler(this, 	this.edtTitle.getText(), 
											this.mmoDescription.getText(),
											this.ddbAssignee.getSelectedId(),
											this.ddbPriority.getSelectedId(),
											this.dpkDueDate.getDate());
		
		this.close();
	},
	
	//--------------------- Setter & Getter ---------------------
	
	getUserName : function()
	{
		return this.ddbAssignee.getSelectedCaption();
	},
	
	setWidth : function(data)
	{
		this._super(data);
		this.initSize();
	},
	
	setHeight : function(data)
	{
		this._super(data);
		this.initSize();
	},
	
	getOnOK : function()
	{
		if (this._onOK == null)
			this._onOK = new pasta.util.EventObj();
		
		return this._onOK;
	},
});
	
})();